package com.support.android.designlibdemo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.support.android.designlibdemo.R;
import com.support.android.designlibdemo.model.TitleListModel;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2015/11/16.
 */
public class TitleListAdapter extends RecyclerView.Adapter<TitleListAdapter.ListHolder> {

    public interface titleCallBack
    {
        void OnSingleClick();
    }
    private List<TitleListModel> mData;
    private Context mContext;
    private titleCallBack callBack;

    public void setCallBack(titleCallBack callBack) {
        this.callBack = callBack;
    }

    public TitleListAdapter(Context context,List<TitleListModel> data) {
        this.mContext = context;
        mData=data;
    }

    public void setmData(List<TitleListModel> mData) {
        this.mData = mData;
    }

    @Override
    public ListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.title_item_layout, parent, false);
        return new ListHolder(view);
    }

    @Override
    public void onBindViewHolder(ListHolder holder, int position) {
        bindData(holder,position);
    }

    private void bindData(ListHolder holder,int position)
    {
        holder.time.setText(mData.get(position).getTime());
        holder.title.setText(mData.get(position).getTitle());
    }
    @Override
    public int getItemCount() {
        return mData.size();
    }

    static class ListHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.time)
        TextView time;
        @Bind(R.id.title)
        TextView title;

        public ListHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}

